package com.group.admin.controller;

import com.group.admin.entity.ShopSpuEntity;
import com.group.admin.service.ShopSpuService;
import com.group.common.utils.R;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * 商品spu表
 *
 * @author gxx
 * @email hongyezhaofang.com
 * @date 2021-11-13 10:36:51
 */
@RestController
@RequestMapping("admin/shopspu")
public class ShopSpuController {
    @Autowired
    private ShopSpuService shopSpuService;


    /*
    查询所有商品规格参数
     */
    @RequestMapping("/spulist")
    public R  spulist(){
        //查询参数全部信息
        List<ShopSpuEntity> list = shopSpuService.list();
        //查询成功打印返回结果
        return R.ok("查询成功").put("data",list);
    }


    /*
    新增商品规格参数
     */
    @RequestMapping("/spuadd")
    public R spuadd(@RequestBody @Validated ShopSpuEntity shopSpuEntity){
        //新增规则参数
        shopSpuService.spuadd(shopSpuEntity);
        //新增成功返回
        return R.ok("新增成功");
    }


    /*
    根据商品id回显
     */
    @RequestMapping("/info/{shopSpuId}")
    public R info(@PathVariable("shopSpuId") Integer shopSpuId){
        ShopSpuEntity shopSpuEntity=shopSpuService.info(shopSpuId);
        return R.ok().setData(shopSpuEntity);
    }


    /*
    修改商品规格参数
     */
    @RequestMapping("/spuupdate")
    public R spuupdate(@RequestBody @Validated ShopSpuEntity shopSpuEntity ){
        //修改规则参数
        shopSpuService.spuupdate(shopSpuEntity);
        //修改成功返回
        return R.ok("修改成功");
    }

    /*
    根据id删除该参数
     */
    @RequestMapping("/spudel/{shopSpuId}")
    public R spudel(@PathVariable("shopSpuId")Integer shopSpuId){
        //根据id去删除参数
        shopSpuService.spudel(shopSpuId);
        //删除成功返回结果
        return R.ok("删除成功");
    }
}
